<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <div id="app">
        <router-link to="/home">主页</router-link>
        <router-link to="/introduce/123">公司介绍1</router-link>
        <router-link to="/introduce/456">公司介绍2</router-link>
        <router-view></router-view>
    </div>
</body>
<script src="./node_modules/vue/dist/vue.js"></script>
<script src="./node_modules/vue-router/dist/vue-router.js"></script>
<script>
    let routes = [
        {
            path:"/home",
            beforeEnter:(to,from,next) => {
                console.log("/home 路由的导航守卫")
                next();
            },
            component:()=>Promise.resolve({
                template:`<h1>主页的内容</h1>`,
                beforeRouteEnter(to,from,next){
                console.log("组件内的导航守卫 进入到主页的路由");
                next();
                },
                beforeRouteUpdate(to,from,next){
                    console.log("组件内的导航守卫 主页路由更新的时候");
                    next();
                },
                beforeRouteLeave(to,from,next){
                    console.log("组件内的导航守卫 离开 /product 路由");
                    next();
                }
            }),
            
        },
        {
            path:"/introduce/:introduceId",
            beforeEnter:(to,from,next) => {
                console.log("/introduce 路由的导航守卫");
                next();
            },
            component:()=>import("./introduce.js")
        },
    ]
    let router = new VueRouter({
        routes
    })
    //1 全局导航守卫
    router.beforeEach((to,from,next)=>{
        console.log("执行全局的导航守卫");
        next();
    })
    let vm = new Vue({
        router,
        el:"#app",
    })
</script>
</html>